<?php
declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://doc.hyperf.io
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Nats\Consumer;
use App\Logic\Admin;
use App\Model\Wxuser;
use Hyperf\Nats\AbstractConsumer;
use Hyperf\Nats\Annotation\Consumer;
use Hyperf\Nats\Message;
use App\Utils\ServerUtil;

/**
 *
 */
class LogConsumer extends AbstractConsumer
{
    public function consume(Message $payload)
    {
        $data = $payload->getBody(); 
        $data = json_decode($data,true);
        $obj = $this->container->get(Admin::class);

        //开协程处理,防止进程阻塞下个逻辑
        co(function () use ($obj, $payload, $data){
            if(empty($data['admin_id']) || empty($data['log'])){
                $payload->reply(json_encode(ServerUtil::nats(1001,'请求参数不对')));
            }else{

                $obj->addLog($data['log'], $data['admin_id']);
                $payload->reply(json_encode(ServerUtil::nats(0,'操作成功')));
            }


        });
        return;
    }
}